package demo1;

import java.util.Objects;

class Student {
    public String name;
    //编译器自动生成的，  重写equals方法  判断是否相等
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
class Person {
}
class Animal {
}
class Dog {}
public class Test {
    public static void main(String[] args) {
        Student student1 = new Student();
        student1.name = "小夜";

        Student student2 = new Student();
        student2.name = "小夜";

        boolean flg = student1.equals(student2);
        System.out.println(flg);

        System.out.println(student1.hashCode());
        System.out.println(student2.hashCode());   //作用是找到两个对象的地址

    }

    public static void func(Object obj) {
        System.out.println(obj);  //输出的是类型和地址

    }
    public static void main1(String[] args) {
        func(new Person());
        func(new Animal());
        func(new Dog());
    }
}
